package db.dbTables;

import core.objects.BaseObject;
import core.objects.Publisher;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class PublisherTable extends AbstractDBTable {

    public static final String COLUMN_ID = "publisher_id";
    final public DbColumn id = new DbColumn(COLUMN_ID, Types.INTEGER, 11, false, this);
    final public DbColumn name = new DbColumn(COLUMN_NAME, Types.VARCHAR, 45, false, this);

    public PublisherTable() {
        super("publisher");
        setIDColumn(id);
    }

    @Override
    public List<DbColumn> getDbColumns() {
        List<DbColumn> list = new ArrayList<DbColumn>();
        list.add(id);
        list.add(name);
        return list;
    }

    @Override
    public BaseObject convertSqlTableToBaseObject(ResultSet resultSet) {
        int id = 0;
        String name = null;

        try {
            id = resultSet.getInt(COLUMN_ID);
            name = resultSet.getString(COLUMN_NAME);
        } catch (SQLException ex) {
            Logger.getLogger(CityTable.class.getName()).log(Level.SEVERE, null, ex);
        }

        return new Publisher(id, name);
    }
}
